<?php
/**
 * Created by Command.
 * User: Vito
 */

namespace app\admin\curd\polling_type;

use app\common\curd\Save;
use app\model\PollingType;

class PollingTypeSave extends Save
{
    //验证器
    protected $validate = [];
    //追加数据
    protected $appendParams = [];
    //允许新增的数据字段
    protected $field = [];


    protected function saveMiddleware($next,$params){

        // print_r($params);
        // die;

        foreach ($params['data'] as $key => $value) {
            
            // halt($key);
            if($key == 0){
                $params['name'] = $value['name'];
            }
            
            // print_r($value);
            // die;
        }
        
        $response = $next($params);

        $this->addContent($response,$params);

        return $response;
    }
    /**
     * @Description: 添加巡检内容
     * @author: xiayu <cb1071403016@126.com>
     * @param [type] $response          //分类数据
     * @param [type] $params            //内容数据
     * @Date: 2022-11-03 09:11:18
     * @version: 1.0.0
     * @return [type]
     */
    protected function addContent($response, $params){

        $pollingType = new PollingType;

        foreach ($params['data'] as $key => $value) {

            // halt($key);
            if ($key != 0 && $value['name'] != '') {
                // $params['name'] = $value['name'];
                $data = [
                    'pid'       => $response['id'],
                    'name'      => $response['name'],
                    'content'   => $value['name']
                ];
                $pollingType->addContent($data);
            }
    }
    return true;
}
}